/**
 * @file holding/List.js
 * @author wangjunjun
 */

import React, { PropTypes, PureComponent } from 'react';
import { Pagination } from 'antd';
import { autobind } from 'core-decorators';

import styles from './tablepagination.less';

const pageSizeOptions = ['15', '25', '35', '45'];

export default class TablePagination extends PureComponent {

  static propTypes = {
    page: PropTypes.object.isRequired,
  }

  static defaultProps = {
  }
  //分页
  @autobind
  handleChangePage(page, pagesize) {
    console.log('page>>>>',page,"pagesize>>>>",pagesize)
    const { location: { query, pathname }, replace } = this.props;
    replace({
      pathname,
      query: {
        ...query,
        currentpage: page,
      },
    });
  }
  //条数
  @autobind
  onShowSizeChange(current, size) {
    console.log('size>>>>',size)
    const { location: { query, pathname }, replace } = this.props;
    replace({
      pathname,
      query: {
        ...query,
        pagesize: size,
        currentpage: 1,
      },
    });
  }

  render() {
    const { page, location: { query: { currentpage, pagesize } }, totalSurfix } = this.props;
    const surfix = (totalSurfix === undefined ? '条记录' : '位交易员');
    return (
      <Pagination
        showSizeChanger
        pageSizeOptions={pageSizeOptions}
        onShowSizeChange={this.onShowSizeChange}
        total={+page.totalnum || 0}
        showTotal={total => ` 共 ${total} ${surfix}`}
        pageSize={page.pagesize ? +page.pagesize : (+pagesize || 0)}
        current={+currentpage || +page.currentpage}
        onChange={this.handleChangePage}
        style={{ marginTop: 10 }}
      />
    );
  }
}
